package com.cictec.middleware.tde.rm.protocol.rm.decode;

import java.nio.ByteBuffer;

import org.apache.mina.core.session.IoSession;

import com.cictec.middleware.commons.utils.BinaryUtils;
import com.cictec.middleware.tde.exception.MessageDecoderException;
import com.cictec.middleware.tde.rm.protocol.AbstractMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage.Header;
import com.cictec.middleware.tde.rm.protocol.annotion.TerminalMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.rm.message.Rm0x04TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.rm.utils.RmBinaryUtils;

/**
 * 
 * @author lhl
 *
 */
@TerminalMessageDecoder(0x04)
public class Rm0x04Decoder extends AbstractMessageDecoder {

	@Override
	public TerminalMessage decode(Header header, ByteBuffer in, IoSession session) throws MessageDecoderException {

		Rm0x04TerminalMessage tum = new Rm0x04TerminalMessage(header);
		tum.setCreateTime(RmBinaryUtils.dwordToDateRM(in));
		tum.setLat(RmBinaryUtils.dwordToLatLngRM(in));
		tum.setLng(RmBinaryUtils.dwordToLatLngRM(in));
		tum.setSpeed(BinaryUtils.unsignedByteToInt(in));
		tum.setAngle(BinaryUtils.unsignedByteToInt(in));
		tum.setAltitude(BinaryUtils.wordToInt(in));
		tum.setMessageType(BinaryUtils.unsignedByteToInt(in));
		tum.setMessageNumber(BinaryUtils.unsignedByteToInt(in));
		tum.setTriggerType(BinaryUtils.unsignedByteToInt(in));
		tum.setReserved(BinaryUtils.wordToInt(in));
		return tum;
	}

}
